﻿using SketchUpAPI.NET.Enums;
using SketchUpAPI.NET.SketchUp.Exception;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SketchUpAPI.NET.Objects
{
    /// <summary>
    /// 字体
    /// </summary>
    /// <remarks>对 SketchUpAPI 中的 SUFontRef 的包装</remarks>
    public class Font : Entity
    {
        #region API 函数
        /// <summary>
        /// 获取字体的名字
        /// </summary>
        /// <param name="font"></param>
        /// <param name="name"><see cref="StringRef"/></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUFontGetFaceName(IntPtr font, ref IntPtr name);

        /// <summary>
        /// 获取字号
        /// </summary>
        /// <param name="font"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUFontGetPointSize(IntPtr font, out long size);

        /// <summary>
        /// 是否加粗
        /// </summary>
        /// <param name="font"></param>
        /// <param name="is_bold"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUFontGetBold(IntPtr font, out bool is_bold);

        /// <summary>
        /// 是否倾斜
        /// </summary>
        /// <param name="font"></param>
        /// <param name="is_italic"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUFontGetItalic(IntPtr font, out bool is_italic);

        /// <summary>
        /// 是否使用文字尺寸
        /// </summary>
        /// <param name="font"></param>
        /// <param name="use_world_size"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUFontGetUseWorldSize(IntPtr font, out bool use_world_size);

        /// <summary>
        /// 文字尺寸
        /// </summary>
        /// <param name="font"></param>
        /// <param name="world_size"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUFontGetWorldSize(IntPtr font, out double world_size);
        #endregion

        /// <summary>
        /// 字体名字
        /// </summary>
        public string Name
        {
            get
            {
                StringRef s = StringRef.Empty;
                SketchUpExceptionHelper.ThrowSUResult(SUFontGetFaceName(Id, ref Id));
                return s.Dispose();
            }
        }

        /// <summary>
        /// 字体点号
        /// </summary>
        public int PointSize
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUFontGetPointSize(Id, out long size));
                return (int)size;
            }
        }

        /// <summary>
        /// 加粗
        /// </summary>
        public bool Bold
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUFontGetBold(Id, out bool bold));
                return bold;
            }
        }

        /// <summary>
        /// 倾斜
        /// </summary>
        public bool Italic
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUFontGetItalic(Id, out bool italic));
                return italic;
            }
        }

        /// <summary>
        /// 是否使用绝对大小
        /// </summary>
        public bool UseWorldSize
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUFontGetUseWorldSize(Id, out bool size));
                return size;
            }
        }

        /// <summary>
        /// 绝对尺寸
        /// </summary>
        public double WorldSize
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUFontGetWorldSize(Id, out double size));
                return size;
            }
        }

        internal Font(IntPtr id) : base(id) { }
    }
}